package com.thb.pay.manage.web.payment;


import com.thb.pay.api.payment.PayTypeServiceApi;
import com.thb.pay.api.payment.vo.req.PayTypePageReq;
import com.thb.pay.api.payment.vo.req.PayTypeReq;
import com.thb.pay.api.payment.vo.resp.PayTypeVo;
import com.thb.pay.core.utils.PageResult;
import com.thb.pay.core.utils.R;
import com.thb.pay.manage.comm.controller.BaseController;
import com.xiaoleilu.hutool.collection.CollUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 支付-类型表 前端控制器
 * </p>
 *
 * @author lucky
 * @since 2019-07-21
 */
@Slf4j
@RestController
@RequestMapping("api/sys/payType")
public class PayTypeController extends BaseController {

    @Autowired
    private PayTypeServiceApi payTypeServiceApi;

    @PostMapping("/list")
    public R list(@RequestBody PayTypePageReq pageReq) {
        PageResult<PayTypeVo> pageResult = payTypeServiceApi.findPage(pageReq);
        return R.okData(pageResult);
    }

    @RequestMapping("/allList")
    public R allList() {
        List<PayTypeVo> resultDataList = payTypeServiceApi.findAllList();
        return R.okData(resultDataList);
    }

    @RequestMapping("/get")
    public R get(@RequestParam("id") Long id) {
        PayTypeVo resultData = payTypeServiceApi.getById(id);
        return R.okData(resultData);
    }

    @PostMapping("/add")
    public R add(@RequestBody PayTypeReq payTypeReq) {
        payTypeServiceApi.add(payTypeReq);
        return R.ok();
    }

    @RequestMapping("/delete")
    public R delete(@RequestParam("payTypeIds") String payTypeIds) {
        List<Long> resIds = parseStrIdsToList(payTypeIds);
        if (CollUtil.isNotEmpty(resIds)) {
            payTypeServiceApi.deleteBatchIds(resIds);
        }
        return R.ok();
    }

    @PostMapping("/update")
    public R update(@RequestBody PayTypeReq payTypeReq) {
        payTypeServiceApi.update(payTypeReq);
        return R.ok();
    }
}
